package com.nondo.dean.order.service;

import java.util.LinkedHashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import com.nondo.dean.common.tool.BeanUtils;
import com.nondo.dean.common.web.View;
import com.nondo.dean.order.model.param.ProductPriceParam;
import com.nondo.dean.order.model.result.PriceResult;

/**
 * 价格管理业务类
 * 
 * @author zhaoljin
 * @date 2018年4月17日
 */
@Component
public class PriceService {

    @Autowired
    RestTemplate restTemplate;

    /**
     * 根据用户和产品ID获取产品折扣信息
     * 
     * @param param {@link ProductPriceParam}
     * @return 产品折扣信息{@link PriceResult}
     */
    public PriceResult getProductBeanById(ProductPriceParam param) {
        PriceResult priceResult = new PriceResult();
        @SuppressWarnings("unchecked")
        View<LinkedHashMap<String, Object>> result =
            restTemplate.postForEntity("http://dean-platform/platform/v1/inner/price/compute/" + param, null,
                View.class).getBody();
        if (result.getCode() == 20000 && result.getData() != null) {
            BeanUtils.copy(result.getData(), priceResult);
        }
        return priceResult;
    }

}
